//package com.molyfun.parents.activity.report;
//
//import android.os.Bundle;
//import android.support.v7.widget.LinearLayoutManager;
//import android.support.v7.widget.RecyclerView;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.LinearLayout;
//
//import com.molyfun.parents.MFPApplication;
//import com.molyfun.parents.R;
//import com.molyfun.parents.activity.common.BaseMainTabFragment;
//import com.molyfun.parents.activity.report.adapter.ReportListAdapter;
//import com.molyfun.parents.activity.report.adapter.ResultAdapter;
//import com.molyfun.parents.activity.report.adapter.TrainingplanAdapter;
//import com.molyfun.parents.rest.RestClient;
//import com.molyfun.parents.rest.bean.ReportBriefListResponse;
//import com.molyfun.parents.rest.bean.ReportResultResponse;
//import com.molyfun.parents.rest.bean.TrainingListResponse;
//import com.molyfun.parents.utils.PreferencesStorageUtil;
//import com.molyfun.parents.view.ThreeTabBar;
//import com.molyfun.parents.view.swipeRefreshLayout.SwipeRefreshLayout;
//
//import butterknife.ButterKnife;
//import butterknife.InjectView;
//import retrofit2.Call;
//import retrofit2.Callback;
//import retrofit2.Response;
//
//public class MainTabReportFragment extends BaseMainTabFragment implements SwipeRefreshLayout.OnRefreshListener, SwipeRefreshLayout.OnLoadListener, ThreeTabBar.ThreeBarClickListener {
//
//    @InjectView(R.id.report_top_bar)
//    ThreeTabBar mReportTopBar;
//    @InjectView(R.id.report_list)
//    RecyclerView mRecyclerView;
//    @InjectView(R.id.empty_layout)
//    LinearLayout mEmptyLayout;
//    @InjectView(R.id.swipe_refresh_layout)
//    SwipeRefreshLayout mSwipeRefreshLayout;
//
//    private LinearLayoutManager mLayoutManager;
//    private ReportListAdapter mReportListAdapter;
//    private ResultAdapter mResultAdapter;
//    private TrainingplanAdapter mTrainingplanAdapter;
//
//    private int mCurrentPage = RestClient.DEFAULT_PAGE;
//    private boolean mHasMoreData = true;
//
//
//    public static MainTabReportFragment newInstance() {
//        return new MainTabReportFragment();
//    }
//
//    @Override
//    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//        if(!PreferencesStorageUtil.isUserEnter(getContext())){
//            return super.onCreateView(inflater, container, savedInstanceState);
//        }
//
//        View view = inflater.inflate(R.layout.fragment_report, container, false);
//        ButterKnife.inject(this, view);
//
//        mSwipeRefreshLayout.setOnRefreshListener(this);
//        mSwipeRefreshLayout.setOnLoadListener(this);
//        mSwipeRefreshLayout.setTopColor(R.color.refresh_color_01, R.color.refresh_color_02,
//                R.color.refresh_color_02, R.color.refresh_color_01);
//        mSwipeRefreshLayout.setBottomColor(R.color.color_transparent, R.color.color_transparent,
//                R.color.color_transparent, R.color.color_transparent);
//        mSwipeRefreshLayout.setMode(SwipeRefreshLayout.Mode.BOTH);
//        mSwipeRefreshLayout.setLoadNoFull(true);
//
//        mLayoutManager = new LinearLayoutManager(getActivity());
//        mRecyclerView.setHasFixedSize(true);
//        mRecyclerView.setLayoutManager(mLayoutManager);
//        mReportListAdapter = new ReportListAdapter(getActivity());
//        mTrainingplanAdapter = new TrainingplanAdapter(getActivity());
//        mResultAdapter = new ResultAdapter(getActivity());
//        mRecyclerView.setAdapter(mReportListAdapter);
//        loadData(mReportTopBar.getCurrentChooseTab(), true);
//        mReportTopBar.setThreeBarClickListener(this);
//        mReportTopBar.initData("评估报告", "训练计划", "训练报告");
//        return view;
//    }
//
//    @Override
//    public void onThreeBarClick(int chooseTab) {
//        loadData(chooseTab, true);
//    }
//
//    @Override
//    public void onParentClickTab() {
//        if(PreferencesStorageUtil.isUserEnter(getContext()) && getView() != null){
//            loadData(mReportTopBar.getCurrentChooseTab(), true);
//        }
//    }
//
//    @Override
//    public void onRefresh() {
//        loadData(mReportTopBar.getCurrentChooseTab(), true);
//        mSwipeRefreshLayout.setRefreshing(false);
//        mSwipeRefreshLayout.setLoading(false);
//    }
//
//    @Override
//    public void onLoad() {
//        mSwipeRefreshLayout.setRefreshing(false);
//        mSwipeRefreshLayout.setLoading(false);
//        if(mHasMoreData){
//            mCurrentPage ++;
//            loadData(mReportTopBar.getCurrentChooseTab(), false);
//        }
//    }
//
//    private void loadData(int currentTab, final boolean isRefresh){
//        switch (currentTab){
//            case ThreeTabBar.ThreeTabChooseTab.BAR_ONE:
//                getEvaluateList(isRefresh);
//                break;
//            case ThreeTabBar.ThreeTabChooseTab.BAR_TWO:
//                getTrainingList(isRefresh);
//                break;
//            case ThreeTabBar.ThreeTabChooseTab.BAR_THREE:
//                getLearnReport(isRefresh);
//                break;
//        }
//    }
//
//    private void getLearnReport(final boolean isRefresh){
//        if(isRefresh){
//            mCurrentPage = RestClient.DEFAULT_PAGE;
//        }
//
//        showProgressDialog();
//        mRecyclerView.setAdapter(mReportListAdapter);
//        Call<ReportBriefListResponse> call = MFPApplication.getInstance().getRestClient().getReportList(mCurrentPage, RestClient.DEFAULT_PAGE_SIZE);
//        call.enqueue(new Callback<ReportBriefListResponse>() {
//            @Override
//            public void onResponse(Call<ReportBriefListResponse> call, Response<ReportBriefListResponse> response) {
//                dismissProgressDialog();
//                if (response.body() != null && response.body().getData() != null && response.body().getData().getRecords() != null) {
//                    if(isRefresh){
//                        if(response.body().getData().getRecords().size() > 0){
//                            mReportListAdapter.refreshData(response.body().getData().getRecords());
//                            mHasMoreData = true;
//                            mEmptyLayout.setVisibility(View.GONE);
//                        }else{
//                            mHasMoreData = false;
//                            mReportListAdapter.clearAll();
//                            mEmptyLayout.setVisibility(View.VISIBLE);
//                        }
//                    }else{
//                        if(response.body().getData().getRecords().size() > 0){
//                            mHasMoreData = true;
//                        }else{
//                            mHasMoreData = false;
//                        }
//                        mReportListAdapter.addAll(response.body().getData().getRecords());
//                    }
//
//                }
//            }
//
//            @Override
//            public void onFailure(Call<ReportBriefListResponse> call, Throwable t) {
//                mReportListAdapter.clearAll();
//                mEmptyLayout.setVisibility(View.VISIBLE);
//                dismissProgressDialog();
//            }
//        });
//    }
//
//    private void getEvaluateList(final boolean isRefresh){
//        if(isRefresh){
//            mCurrentPage = RestClient.DEFAULT_PAGE;
//        }
//        mRecyclerView.setAdapter(mResultAdapter);
//        showProgressDialog();
//
//        Call<ReportResultResponse> call = MFPApplication.getInstance().getRestClient().getEvaluateList(mCurrentPage, RestClient.DEFAULT_PAGE_SIZE);
//        call.enqueue(new Callback<ReportResultResponse>() {
//            @Override
//            public void onResponse(Call<ReportResultResponse> call, Response<ReportResultResponse> response) {
//                dismissProgressDialog();
//                if (response.body() != null && response.body().getData() != null && response.body().getData().getRecords() != null) {
//                    if(isRefresh){
//                        if(response.body().getData().getRecords().size() > 0){
//                            mResultAdapter.refreshData(response.body().getData().getRecords());
//                            mHasMoreData = true;
//                            mEmptyLayout.setVisibility(View.GONE);
//                        }else{
//                            mHasMoreData = false;
//                            mResultAdapter.clearAll();
//                            mEmptyLayout.setVisibility(View.VISIBLE);
//                        }
//                    }else{
//                        if(response.body().getData().getRecords().size() > 0){
//                            mHasMoreData = true;
//                        }else{
//                            mHasMoreData = false;
//                        }
//                        mResultAdapter.addAll(response.body().getData().getRecords());
//                    }
//
//                }
//            }
//
//            @Override
//            public void onFailure(Call<ReportResultResponse> call, Throwable t) {
//                mResultAdapter.clearAll();
//                mEmptyLayout.setVisibility(View.VISIBLE);
//                dismissProgressDialog();
//            }
//        });
//
//    }
//
//    private void getTrainingList(final boolean isRefresh){
//        if(isRefresh){
//            mCurrentPage = RestClient.DEFAULT_PAGE;
//        }
//        mRecyclerView.setAdapter(mTrainingplanAdapter);
//        showProgressDialog();
//
//        Call<TrainingListResponse> call = MFPApplication.getInstance().getRestClient().getTrainingList(mCurrentPage, RestClient.DEFAULT_PAGE_SIZE);
//        call.enqueue(new Callback<TrainingListResponse>() {
//            @Override
//            public void onResponse(Call<TrainingListResponse> call, Response<TrainingListResponse> response) {
//                dismissProgressDialog();
//                if (response.body() != null && response.body().getData() != null && response.body().getData().getRecords() != null) {
//                    if(isRefresh){
//                        if(response.body().getData().getRecords().size() > 0){
//                            mTrainingplanAdapter.refreshData(response.body().getData().getRecords());
//                            mHasMoreData = true;
//                            mEmptyLayout.setVisibility(View.GONE);
//                        }else{
//                            mHasMoreData = false;
//                            mTrainingplanAdapter.clearAll();
//                            mEmptyLayout.setVisibility(View.VISIBLE);
//                        }
//                    }else{
//                        if(response.body().getData().getRecords().size() > 0){
//                            mHasMoreData = true;
//                        }else{
//                            mHasMoreData = false;
//                        }
//                        mTrainingplanAdapter.addAll(response.body().getData().getRecords());
//                    }
//
//                }
//            }
//
//            @Override
//            public void onFailure(Call<TrainingListResponse> call, Throwable t) {
//                mTrainingplanAdapter.clearAll();
//                mEmptyLayout.setVisibility(View.VISIBLE);
//                dismissProgressDialog();
//            }
//        });
//
//    }
//
//}
